<div id="templatemo_upcomming_event" class="container_wapper">
    <div class="container">
        <h1 align="center" style="font-family: calibri; margin-bottom: 20px;"> -------------------Ada <?= $pesan_baru ?> Pesan Baru-------------------</h1>        
        <table id="table-content">
            <tr>
                <td colspan="5">
                    Cari Pesan Untuk Tanggal : 
                    <a href='<?= site_url("/pesan/pesan_masuk") ?>'>Hari ini</a> | 
                    <a href='<?= site_url("/pesan/pesan_masuk/1") ?>'>Kemarin</a> | 
                    <?php
                    for ($i = 2; $i <= 6; $i++) {
                        echo "<a href='" . site_url("/pesan/pesan_masuk/" . $i) . "' >" . date('Y-m-d', strtotime("-" . $i . " days")) . "</a> | ";
                    }
                    ?>    
                </td>
            </tr>
            <tr>
                <td colspan="5"><br/><br/><a href='<?= site_url("/pesan/kontak_add/-") ?>'>Add New Kontak</a></td>
            </tr>
            <tr>
                <td><h3>No</h3></td>
                <td><h3>Tanggal</h3></td>
                <td><h3>Pengirim</h3></td>
                <td><h3>Isi Pesan</h3></td>
                <td><h3>&nbsp;</h3></td>
            </tr>
            <?php
            $n = 0;
            foreach ($pesan_masuk as $data) {
                ?>            
                <tr>
                    <td><?= $n + 1; ?></td>
                    <td><?= $data->date_created; ?></td>
                    <?php
                    if (trim($data->nama_kontak) !== "") {
                        echo "<td>" . ($data->nama_kontak . " (<a href='" . site_url("pesan/kontak_detil/" . $data->sender) . "'>" . $data->sender . " / " . $data->group_kontak . "</a>)") . "</td>";
                    } else {
                        echo "<td>" . ($data->sender . " (<a href='" . site_url("pesan/kontak_add/" . $data->sender) . "'>Edit Nama</a>)") . "</td>";
                    }
                    ?>
                    <td><?php
                        if ($data->status == "0")
                            echo "<b>" . substr($data->isi, 0, 120) . "...</b>";
                        else
                            echo "" . substr($data->isi, 0, 120) . "...";
                        ?>
                    <td>
                        <?php
                        if ($data->status == "0") {
                            echo "<b><a href='" . site_url("pesan/pesan_masuk_jawab/" . $data->sender . "/" . $data->id_komplain) . "'>Jawab Pesan</a></b>";
                        } else if ($data->status == "1") {
                            echo "<a href='" . site_url("pesan/pesan_masuk_jawab/" . $data->sender . "/" . $data->id_komplain) . "'>History</a>";
                        }
                        ?>
                    </td>
                </tr>
                <?php
                $n++;
            }
            ?>
        </table>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        setInterval(function() {
            location.reload();
        }, 15000);

<?php
if ($pesan_baru > 0) {
    ?>
            var audioElement = document.createElement('audio');
            audioElement.setAttribute('src', '<?=base_url('/static/alarm.mp3')?>');
            audioElement.setAttribute('autoplay', 'autoplay');
            //audioElement.load()

            $.get();

            audioElement.addEventListener("load", function() {
                audioElement.play();
            }, true);
    <?php
}
?>
    });
</script>
</body>
</html>